package splash;

import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author SEP
 */
public class CanvasSplash extends Canvas implements Runnable{
   Displayable startScreen;
   Display display;
   Image ic,cero,veinte,cuarenta,sesenta,ochenta,cien;
   int cargado;
   Thread pausa;
   
   public CanvasSplash(Display display) {
      this.display = display;
      try {
           ic = Image.createImage("icono/micartera_ico_carga.png");
           cero = Image.createImage("imagenescarga/ceroporciento.png");
           veinte = Image.createImage("imagenescarga/veinteporciento.png");
           cuarenta = Image.createImage("imagenescarga/cuarentaporciento.png");
           sesenta = Image.createImage("imagenescarga/sesentaporciento.png");
           ochenta = Image.createImage("imagenescarga/ochentaporciento.png");
           cien = Image.createImage("imagenescarga/cienporciento.png");
          }
      catch (IOException e) {
           System.out.println("Error al cargar imágenes");
         }
   }
   public void start(){
       pausa=new Thread(this);
       pausa.start();
    }

   public void setStartScreen(Displayable startScreen) {
        this.startScreen = startScreen;
    }

    public void paint(Graphics g) {

        g.setColor(0,0,0); //Selecciono el color negro
        g.fillRect(0,0,getWidth(),getHeight()); //limpiamos pantalla
          if (cargado<=100){
              g.drawImage(ic, getWidth()/4+10, getHeight()/4, Graphics.TOP |Graphics.LEFT);//Muestro el icono de la aplicación
              g.setColor(255,255,255); //Selecciono el color blanco
          }
          if (cargado==0) {
            g.drawString("Carga      0%",getWidth()/4+8,getHeight()/4+120,Graphics.TOP|Graphics.LEFT);
            g.drawImage(cero, getWidth()/4, getHeight()/4+150, Graphics.TOP |Graphics.LEFT);
          }
          if (cargado==20){
            g.drawString("Carga     20%",getWidth()/4+8,getHeight()/4+120,Graphics.TOP|Graphics.LEFT);
            g.drawImage(veinte, getWidth()/4, getHeight()/4+150, Graphics.TOP |Graphics.LEFT);
          }
          if (cargado==40){
            g.drawString("Carga     40%",getWidth()/4+8,getHeight()/4+120,Graphics.TOP|Graphics.LEFT);
            g.drawImage(cuarenta, getWidth()/4, getHeight()/4+150, Graphics.TOP |Graphics.LEFT);
          }
          if (cargado==60){
            g.drawString("Carga     60%",getWidth()/4+8,getHeight()/4+120,Graphics.TOP|Graphics.LEFT);
            g.drawImage(sesenta, getWidth()/4, getHeight()/4+150, Graphics.TOP |Graphics.LEFT);
          }
          if (cargado==80){
            g.drawString("Carga     80%",getWidth()/4+8,getHeight()/4+120,Graphics.TOP|Graphics.LEFT);
            g.drawImage(ochenta, getWidth()/4, getHeight()/4+150, Graphics.TOP |Graphics.LEFT);
          }
          if (cargado==100){
            g.drawString("Carga    100%",getWidth()/4+8,getHeight()/4+120,Graphics.TOP|Graphics.LEFT);
            g.drawImage(cien, getWidth()/4, getHeight()/4+150, Graphics.TOP |Graphics.LEFT);
          }
    }

    public void run(){
       
       cargado=0;
        try{
           do{
              pausa.sleep(2000); cargado+=20; repaint();
           }while (cargado<100);
        //CAMBIAR DE PANTALLA
        }
        catch (InterruptedException e) {
          System.out.println("Error al iniciar la aplicación");
        }
    }
}

